import Model.HighScores;
import Model.Score;

import javax.swing.*;
import java.awt.*;
import java.util.Collections;

/**
 * Created by wulf on 24.10.2014.
 */
public class HighScorePanel extends JPanel {
    public static final int WIDTH = 200;
    public static final int HEIGHT = 200;
    public static final int SCALE = 2;
    JLabel note = new JLabel("Es sind keine Einträge vorhanden!");
    JTextArea position = new JTextArea();
    JTextArea name = new JTextArea();
    JTextArea value = new JTextArea();

    public HighScorePanel(){
        super();
        setLayout(new GridLayout(1,3));

        setPreferredSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
        setFocusable(true);
        requestFocus();

        addContent();
    }

    /**
     * Hinzufügen der Ergebnisse zum Panel
     */
    public void addContent(){
        HighScore hs = new HighScore();
        HighScores highScores = hs.getOnlineScores();
        Collections.sort(highScores.Scores, Collections.reverseOrder());

        int i = 1;
        if (highScores.Scores != null && highScores.Scores.size() > 0){
            this.add(position);
            this.add(name);
            this.add(value);

            position.append("Position\n");
            name.append("Name\n");
            value.append("Ergebnis\n");

            for(Score score : highScores.Scores) {
                position.append(i++ + "\n");
                name.append(score.Name + "\n");
                value.append(score.Value + "\n");
            }
        }else{
            this.add(note);
        }
        position.setEditable(false);
        name.setEditable(false);
        value.setEditable(false);
    }
}
